package com.aqie.easy.string;

/**
 *
 *
 * 821. 字符的最短距离
 * 字符串中每个字符 到指定字符最短距离
 * todo
 */
public class ShortestToChar {
    public int[] shortestToChar(String S, char C) {
        int left = -1;
        int right = -1;
        int[] result = new int[S.length()];
        for (int i = 0; i < result.length; i++) {
            if(i>right){
                for (int j=i;j<result.length;j++){
                    if(S.charAt(j)==C){
                        left = right;
                        right = j;
                        break;
                    }
                }
            }
            if(left==-1){
                result[i] = Math.abs(right-i);
            }else{
                result[i] = Math.abs(Integer.min(right-i,i-left));
            }
        }
        return result;
    }

    public static void main(String[] args) {
        String S = "loveleetcode";
        char C = 'e';
    }
}
